package com.ruoyi.crm.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.crm.domain.Contract;
import com.ruoyi.crm.domain.dos.AscriptionDos;
import com.ruoyi.crm.domain.dos.ChannelStatisticsDos;
import com.ruoyi.crm.domain.dos.DeptStatisticsDos;
import com.ruoyi.crm.domain.dos.SubjectGroupNumDos;
import com.ruoyi.crm.domain.dto.*;
import com.ruoyi.crm.domain.vo.ContractStatisticsVO;
import com.ruoyi.crm.service.IContractService;
import com.ruoyi.crm.service.ReportDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author mr.huang [jie88888822@163.com]
 * @devTime 2022-06-16
 */
@Slf4j
@RestController
@RequestMapping("/report")
public class ReportController extends BaseController {
	@Resource
	private ReportDataService reportDataService;
	@Resource
	private IContractService iContractService;

	/**
	 * 露斗图
	 * @param beginCreateTime
	 * @param endCreateTime
	 * @return
	 */
	@GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
	public AjaxResult getVulnerabilityMap(@PathVariable("beginCreateTime") String beginCreateTime,
										  @PathVariable("endCreateTime") String endCreateTime){
		return reportDataService.getVulnerabilityMap(beginCreateTime,endCreateTime);
	}

	@GetMapping("/contractStatisticsList")
	public TableDataInfo contractStatisticsList(Contract contract){
		startPage();
		List<Contract> contracts = iContractService.selectContractList(contract);
		return getDataTable(contracts);
	}

	@GetMapping("/contractStatistics/{beginTime}/{endTime}")
	public ContractStatisticsVO contractStatistics(@PathVariable String beginTime,
												   @PathVariable String endTime){
		return iContractService.contractStatistics(beginTime, endTime);
	}

	/**
	 * 客户统计
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	@GetMapping("/subjectStatistics/{beginTime}/{endTime}")
	public List<SubjectGroupNumDos> subjectStatistics(@PathVariable String beginTime,
													  @PathVariable String endTime){
		return iContractService.subjectStatistics(beginTime,endTime);
	}

	/**
	 * 销售统计
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	@GetMapping("/salesStatistics/{beginTime}/{endTime}")
	public ContractStatisticsVO salesStatistics(@PathVariable String beginTime,
											@PathVariable String endTime){
		return iContractService.salesStatistics(beginTime, endTime);
	}

	/**
	 * 销售统计：部门列表
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	@GetMapping("/deptStatisticsList/{beginTime}/{endTime}")
	public TableDataInfo deptStatisticsList(@PathVariable String beginTime,
											@PathVariable String endTime){
		startPage();
		List<DeptStatisticsDos> dosList = reportDataService.deptStatisticsList(beginTime, endTime);
		return getDataTable(dosList);
	}

	/**
	 * 销售统计：渠道列表
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	@GetMapping("/channelStatisticsList/{beginTime}/{endTime}")
	public TableDataInfo channelStatisticsList(@PathVariable String beginTime,
											@PathVariable String endTime){
		startPage();
		List<ChannelStatisticsDos> channelStatisticsDos =
				reportDataService.channelStatisticsList(beginTime,endTime);
		return getDataTable(channelStatisticsDos);
	}

	/**
	 * 销售统计：归属人列表
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	@GetMapping("/ownerShipStatisticsList/{beginTime}/{endTime}")
	public TableDataInfo ownerShipStatisticsList(@PathVariable String beginTime,
											@PathVariable String endTime){
		startPage();
		List<AscriptionDos> ascriptions = reportDataService.ownerShipStatisticsList(beginTime,endTime);
		return getDataTable(ascriptions);
	}

	/**
	 * 线索统计
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	@GetMapping("/cluesStatistics/{beginTime}/{endTime}")
	public ContractStatisticsVO cluesStatistics(@PathVariable String beginTime,
												 @PathVariable String endTime){
		return reportDataService.cluesStatistics(beginTime, endTime);
	}

	/**
	 * 线索列表
	 * @return
	 */
	@GetMapping("/cluesStatisticsList")
	public TableDataInfo cluesStatistics(ClueDTOQuery clueDTOQuery){
		startPage();
		List<ReportClueDTO> reportClueDTOS = reportDataService.cluesStatisticsList(clueDTOQuery);
		log.info("<=============cluesStatistics",reportClueDTOS);
		return getDataTable(reportClueDTOS);
	}

	/**
	 * 渠道统计列表
	 * @param
	 * @param
	 * @return
	 */
	@GetMapping("/activityStatisticsList")
	public TableDataInfo activityStatisticsList(@RequestParam("code") String code,
												@RequestParam("name") String name){
		startPage();
		List<ChannelDTO> channelDTOS = reportDataService.activityStatisticsList(code,name);
		return getDataTable(channelDTOS);
	}

	/**
	 * 渠道统计 1
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	@GetMapping("/chanelStatistics/{beginTime}/{endTime}")
	public ContractStatisticsVO chanelStatistics(@PathVariable String beginTime,
												 @PathVariable String endTime){
		// TODO 待完成没有数据参数
		return null;
	}

	/**
	 * 渠道统计 2
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	@GetMapping("/activityStatistics/{beginTime}/{endTime}")
	public ContractStatisticsVO activityStatistics(@PathVariable String beginTime,
												   @PathVariable String endTime){
		// TODO 待完成没有数据参数
		return null;
	}
}
